﻿using AutoMapper;
using MediatR;
using S.Archives.Domain.S.ArchivesDto;
using S.Archives.Infrstructre.InterFace;
using S.Archives.Read.Api.Application.Command;

namespace S.Archives.Read.Api.Application.CommandHandlers
{
    public class MatingspeciesSelCommandHandler : IRequestHandler<MatingspeciesSelCommand, List<EnumStringDto>>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public MatingspeciesSelCommandHandler(ISheepFileRepository shepFileRepository,IMapper mapper)
        {
            this.sheepFileRepository= shepFileRepository;
            this.mapper = mapper;

        }

        public async Task<List<EnumStringDto>> Handle(MatingspeciesSelCommand request, CancellationToken cancellationToken)
        {
            var list = sheepFileRepository.GetAllAsync().Result;
            if (request.FileType > 0)
            {
                list = list.Where(x => x.FileType == request.FileType).ToList();
            }
            list = list.Where(x=>x.ReproductiveState<=6&&x.PresenceState==2).ToList();



            List<EnumStringDto> enumDto = new List<EnumStringDto>();
            enumDto = mapper.Map<List<EnumStringDto>>(list);
            return enumDto;
        }
    }
}
